#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<vector>
using namespace std;
int flag = 1;
int n;
vector<int> ret;
int nums[1001];
bool dfs(int left, int right)
{
    if (left > right) return true;
    int l = left + 1, r = right;
    if (flag)
    {
        while (r > left && nums[r] >= nums[left]) r--;
        while (l <= right && nums[l] < nums[left]) l++;
    }
    else
    {
        while (r > left && nums[r] < nums[left]) r--;
        while (l <= right && nums[l] >= nums[left]) l++;
    }
    if (l - r != 1) return false;
    if (dfs(left + 1, r) && dfs(l, right)) ret.push_back(nums[left]);
    return true;
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> nums[i];
    if (!dfs(0, n - 1))
    {
        flag = 0;
        if (dfs(0, n - 1)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else cout << "YES" << endl;
    if ((int)ret.size() == n)
        for (int i = 0; i < n; i++)
        {
            if (i == 0) cout << nums[i];
            else cout << " " << nums[i];
        }
    return 0;
}